public class WaitAndNotify {
    public static void main(String[] args) {
        Object locker = new Object();
        Thread thread1 = new Thread(() -> {
            synchronized (locker) {
                System.out.println("thread1:wait之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("thread1:wait之后");
            }
        });
        thread1.start();
        Thread thread2 = new Thread(() -> {
            synchronized (locker) {
                System.out.println("thread2:wait之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("thread2:wait之后");
            }
        });
        thread2.start();
        Thread thread3 = new Thread(() -> {
            synchronized (locker) {
                System.out.println("thread3:wait之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("thread3:wait之后");
            }
        });
        thread3.start();
        Thread thread4 = new Thread(() -> {
            synchronized (locker) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("notify之前");
                locker.notifyAll();
                System.out.println("notify之后");
            }
        });
        thread4.start();
    }
}
